
//1472.设计浏览器历史记录
class BrowserHistory {
    //使用两个栈来实现
    stack<string> _back;  //back回退时访问的网站
    stack<string> _forward;   //forward前进时访问的网站
    string now_str;  //now_str表示当前访问的网站
public:
    BrowserHistory(string homepage) {
        now_str=homepage;
    }
    
    void visit(string url) {
        while(!_forward.empty()) _forward.pop();
        _back.push(now_str);
        now_str=url;
    }
    
    string back(int steps) {
        while(steps&&!_back.empty())  
        {
            _forward.push(now_str);  //间当前网址加入到forward队列中
            now_str=_back.top();     //网址向后退,修改当前所在网址
            _back.pop();        
            steps--;
        }
        return now_str;
    }
    
    string forward(int steps) {
        while(steps&&!_forward.empty())
        {
            _back.push(now_str);
            now_str=_forward.top();
            _forward.pop();
            steps--;
        }
        return now_str;
    }
};

/**
 * Your BrowserHistory object will be instantiated and called as such:
 * BrowserHistory* obj = new BrowserHistory(homepage);
 * obj->visit(url);
 * string param_2 = obj->back(steps);
 * string param_3 = obj->forward(steps);
 */